package cn.tedu.charging.order.dao.impl;


import cn.tedu.charging.common.consts.OrderStatus;
import cn.tedu.charging.order.dao.mapper.ChargingBillFailMapper;
import cn.tedu.charging.order.dao.mapper.ChargingBillSuccessMapper;
import cn.tedu.charging.order.dao.repository.OrderRepository;
import cn.tedu.charging.order.pojo.po.ChargingBillFailPo;
import cn.tedu.charging.order.pojo.po.ChargingBillSuccessPo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository(value = "orderRepository")
public class OrderRepositoryImpl implements OrderRepository {

    @Autowired
    private ChargingBillSuccessMapper chargingBillSuccessMapper;
    @Autowired
    private ChargingBillFailMapper chargingBillFailMapper;
    @Override
    public Integer updateStatusFromDead(String orderNo) {
        ChargingBillSuccessPo chargingBillSuccessPo = new ChargingBillSuccessPo();
        chargingBillSuccessPo.setBillStatus(OrderStatus.CHARGING_STATUS_EXCEPTION);

        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("bill_id",orderNo);
        updateWrapper.eq("bill_status", OrderStatus.CHARGING_ING);

        int i = chargingBillSuccessMapper.update(chargingBillSuccessPo, updateWrapper);
        return i;
    }

    @Override
    public ChargingBillSuccessPo getSuccessOrderByOrder(String orderNo) {
        QueryWrapper<ChargingBillSuccessPo> queryWrapper =  new QueryWrapper<>();
        queryWrapper.eq("bill_id",orderNo);
        ChargingBillSuccessPo chargingBillSuccessPo = chargingBillSuccessMapper.selectOne(queryWrapper);
        return chargingBillSuccessPo;
    }

    @Override
    public ChargingBillFailPo getFailOrderByOrder(String orderNo) {
        QueryWrapper<ChargingBillFailPo> queryWrapper =  new QueryWrapper<>();
        queryWrapper.eq("bill_id",orderNo);
        ChargingBillFailPo chargingBillFailPo  = chargingBillFailMapper.selectOne(queryWrapper);
        return chargingBillFailPo;
    }


}
